<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<c:choose>
	<c:when test="${null != actionBean.queryGroupResult && not empty actionBean.queryGroupResult.paginatedList}">
		<c:set var="lastPageNumber" value="${actionBean.queryGroupResult.totalPageCount}"/>
		<c:set var="currentPageNumber" value="${actionBean.queryGroupResult.pageNumber}"/>
		<c:set var="prePageNumber" value="${actionBean.queryGroupResult.pageNumber - 1}"/>
		<c:set var="nextPageNumber" value="${actionBean.queryGroupResult.pageNumber + 1}"/>
		
					<div id="paginationBar">
						<input type="button" id="group.firstPageBtn" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
						<input type="button" id="group.prePageBtn" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
						第 <input type="text" id="group.currentPageText" value="${currentPageNumber }" size="3" maxlength="4"> / ${lastPageNumber} 頁
						<input type="button" id="group.nextPageBtn" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
						<input type="button" id="group.lastPageBtn" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />
					</div>
					
						<table id="listTable">
							<tr>
								<th>業者代號</th>
								<th>業者名稱</th>
							</tr>
							<c:forEach items="${actionBean.queryGroupResult.paginatedList}" var="viewObj" varStatus="rowstat">
							<tr>
								
								<td><a id="returnGroupNo-<c:out value="${viewObj.groupNo}"/>" href="javascript: void(0);"><c:out value="${viewObj.groupNo}"/></a>
									<input type="hidden" id="returnGroupName-<c:out value="${viewObj.groupNo}"/>" value="<c:out value="${viewObj.groupName}"/>"/>						
								
								</td>
								
								<td><a id="returnGgoupName-<c:out value="${viewObj.groupName}"/>"><c:out value="${viewObj.groupName}"/> </a> </td>
							</tr>
							</c:forEach>
						</table>
						
					<div id="paginationBar">
						<input type="button" id="group.firstPageBtn1" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
						<input type="button" id="group.prePageBtn1" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
						第 <input type="text" id="group.currentPageText1" value="${currentPageNumber }" size="3" maxlength="4"> / ${lastPageNumber} 頁
						<input type="button" id="group.nextPageBtn1" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
						<input type="button" id="group.lastPageBtn1" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />
					</div>
							
		<script type="text/javascript">
		<!--
		$(document).ready(function() {
			
			$("[id^='group.firstPageBtn']").click(function() {
				doQueryGroupAction(1);
			});
			
			$("[id^='group.prePageBtn']").click(function() {
				doQueryGroupAction(<c:out value='${prePageNumber}'/>);
			});
			
			$("[id^='group.nextPageBtn']").click(function() {
				doQueryGroupAction(<c:out value='${nextPageNumber}'/>);
			});
			
			$("[id^='group.lastPageBtn']").click(function() {
				doQueryGroupAction(<c:out value='${lastPageNumber}'/>);
			});
			
			$("[id^='group.currentPageText']").change(function() {

				var value = this.value;
				if (value != ''){
					value = value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
					var intRegex = /^\d+$/;
					if(!intRegex.test(value)) {
						alert('頁數必須是整數');
						return ;
					}
					
					value = parseInt(value, 10);
					
					if (value < 1){
						alert('頁數必須是大於1');
						return ;
					}
					else if (value > <c:out value='${lastPageNumber}'/>){
						alert('頁數必須是小於總頁數 (<c:out value='${lastPageNumber}'/>)');
						return ;
					}
					else if (value != <c:out value='${currentPageNumber}'/>){
						doQueryGroupAction(value);
					}
				}
				else{
					alert('頁數不可為空白');
					return;
				}
			});
			
			$("[id^='returnGroupNo-']").click(function() {
				var gno = this.id.substring(14);
				var nameId = "#returnGroupName-" + gno;	
				$("#group\\.groupNo").val(gno);
				$("#hidden\\.qryGroup\\.groupName\\.span").html($(nameId).val());
				$("#findGroupDiv" ).dialog( "close" );
				
			});		
			
			
			$("#listTable").each(function(i){
				$(this).find("th:first-child").addClass("first");
				$(this).find("td:first-child").addClass("first");
				$(this).find("tr:has(td):odd").addClass("odd");
				$(this).find("tr:has(td):even").addClass("even");
			});
		});
		//-->
		</script>
	</c:when>
	<c:otherwise>
			<table id="groupListTable">
				<tr>
					<th>
						查無資料
					</th>
				</tr>
			</table>
	</c:otherwise>
</c:choose>